<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<button>点击发送</button>
<script>
let button = document.getElementsByTagName('button')[0]
let xhr = null
let isSending = false
button.addEventListener('click',()=>{
    if(isSending){
       xhr.abort()  //如果正在发送请求，则取消本次请求
    }
    xhr = new XMLHttpRequest()
    isSending = true
    xhr.responseType = 'json'
    xhr.open('get','http://localhost:3000/user?id=gailun')
    xhr.send()
    xhr.onreadystatechange = function(){
        if(xhr.readyState === 4){
            isSending = false
            console.log(xhr.response)
        }
    }
})

</script>
</body>
</html>